require 'cgi'

Dir[ File.dirname( __FILE__ ) + '/g_translate/*.rb' ].each do |file| 
  require file
end

module GTranslate
  # Convenience method. Basically proxies to GTranslate::Translator.new
  # and executes translate
  
  # ==== Parameters
  # text<String>::
  #   The text you want to be translated
  # opts<Hash>:: An options hash (see below)
  # 
  # ==== Options (opts)
  # :from<String>:: Source language in iso_639_2 format
  # :to<String>:: Target language in iso_639_2 format
  #  
  # ==== Returns
  # String:: the translated text in the language of target
  #—
  # @public
  def self.translate( text, opts = {} )
    assert_valid_options!( opts )
    Translator.new( text, opts[:from], opts[:to] ).translate
  end
  
  protected
    def self.assert_valid_options!( opts )
      unknown_keys = opts.keys - [ :from, :to ]
      
      unless unknown_keys.empty?
        raise ArgumentError, "Unknown keys #{unknown_keys.inspect}"
      end
      
      missing_keys = [ :from, :to ] - opts.keys
      
      unless missing_keys.empty?
        raise ArgumentError, "Keys #{missing_keys.inspect} are all required"
      end
    end
end